<script>
import baseHome from "@/view/home/home";
import { mapActions } from "vuex";
export default {
  extends: baseHome,

  created() {
    this.goToHome();
  },

  methods: {
    ...mapActions(["handleAccess", "handleClientLogOut"]),
    goToHome() {
      let name = "xd-settle";
      let access = this.getRole();
      if (access) {
        this.handleAccess(access);
        if (access == "wash") {
          name = "xd-settle";
        } else if (access == "hospital") {
          name = "xd-y-put-in";
        } else if (access == "admin") {
          name = "xd-settle";
        }
        this.$router.push({
          name: name
        });
      } else {
        this.handleClientLogOut();
        this.$router.push({
          name: "login"
        });
      }
    },

    getRole() {
      let access,
        lx = parseInt(this.$store.state.user.userInfo.data.lx);
      if (lx == 0) {
        access = "admin";
      } else if (lx == 1) {
        access = "wash";
      } else if (lx == 2) {
        access = "hospital";
      }
      return access;
    }
  }
};
</script>
